package com.bsoft.controller.XML;

import com.bsoft.Exception.CommonException;
import com.bsoft.utils.XmlMapUtils;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping(value = "XML/Base")
public class XmlBaseController {

    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    @RequestMapping(value = "getValue", produces = "application/xml;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String getValue() throws Exception {
        String ss = "是否触发事件,消息";

        Map<String, Object> json = new HashMap<>();
        json.put("Code", "OK");
        json.put("Message", "成功");
        if (1 != 0) {
            throw new CommonException("Xml格式全局异常抛出!");
        }

        int a = 1 / 1;

        Document document = XmlMapUtils.map2xml(json, "BSXml");

        return XmlMapUtils.formatXml(document);
    }


    @RequestMapping("/getValue2/jk")
    public String getValue2() {
        String ss = "是否出发事件";

        return "ok";
    }


}
